package com.itheima.controller;

import com.itheima.pojo.Dept;
import com.itheima.pojo.MyResponseResult;
import com.itheima.service.DeptService;
import com.itheima.utils.MyThreadLocalUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 部门管理Controller
 */
@RestController
@RequestMapping("/depts")
//@Slf4j
public class DeptController {
    @Autowired
    private DeptService deptService;
    @GetMapping
     public MyResponseResult<List<Dept>> selectAll(){
        Map<String, Object> value = MyThreadLocalUtils.getValue();
        System.out.println("从ThreadLocal中获取的令牌解析结果是：=========================="+value);
//        log.debug("日志");
        //参（无）
        //调
         List<Dept> depts = deptService.setAll();
         //响
         return MyResponseResult.ok(depts);
     }
     @DeleteMapping("/{id}")
     public MyResponseResult<Object> delById(@PathVariable Integer id) throws ParseException {
        int i = deptService.delById(id);
        return i>=1?MyResponseResult.ok("ok"):MyResponseResult.error(id+"为的部门删除失败");
     }
     @PostMapping
    public MyResponseResult<Object> insertDept(@RequestBody Dept dept){
       int i = deptService.insertDept(dept);
       return  i>=1?MyResponseResult.ok(dept.getId()):MyResponseResult.error("添加部门失败");
     }


}
